package org.example.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author 莫磊
 * @date 2025/8/10
 * @description
 */
@RestController// 等于Controller和ResponseBody
public class ResponseBodyController {

	/**
	 * servlet原生api
	 */
	@RequestMapping("/testServlet")
	public void testServlet(HttpServletResponse response) throws IOException {
		response.getWriter().write("hello world");
	}

	/**
	 * springMVC替代servlet原生api
	 * 直接将字符串返回给浏览器
	 */
	@RequestMapping("/testResponseBody")
	@ResponseBody
	public String testResponseBody() {
		return "hello world";
	}
}
